/**
 * 微信端个人中心-账号管理
 */
$(function(){
	
	//选择提现到银行卡
	$("#withdraw_bank").on("click",function(){
		window.location.href = rootPath + "/wx/my/wxCustomerAccount/toWithdrawAccount?accountType=bank";
	});
	
	//选择提现到支付宝
	$("#withdraw_alipay").on("click",function(){
		window.location.href = rootPath + "/wx/my/wxCustomerAccount/toWithdrawAccount?accountType=alipay";
	});
	
	//选择提现账号类型返回
	$("#withdraw_type_back").on("click",function(){
		window.location.href = rootPath + "/wx/my/wxWallet/toMyWallet";
	});
	
	//选择提现账号返回按钮
	$("#withdraw_account_back").on("click",function(){
		window.location.href = rootPath + "/wx/my/wxWalletWithdraw/toSelectAccountType";
	});
	
	//提现提交页面（提现账户类型为支付宝）
	$("#withdraw_alipay_back").on("click",function(){
		window.location.href = rootPath + "/wx/my/wxCustomerAccount/toWithdrawAccount?accountType=alipay";
	});
	
	//提现提交页面（提现账户类型为银行卡）
	$("#withdraw_bank_back").on("click",function(){
		window.location.href = rootPath + "/wx/my/wxCustomerAccount/toWithdrawAccount?accountType=bank";
	});
	
	//选择账号点击“√”效果
	$('.yhk_list ul li').click(function(){
		$(this).addClass('current');
		$(this).siblings().removeClass('current');
	});
	
	//点击全部提现
	$("#allWithdraw").on("click",function(){
		//当前账号余额
		var balance = $("#getableMoney").val();
		$("#withdrawMoney").val(balance);
	});
	
	//填写提现信息
	$("#withdrawBth").on("click",function(){
		//提现金额
		var withdrawMoney = $('#withdrawMoney').val();
		//提现账号id
		var accountId = $("#accountId").val();
		
		//判断提现金额不可为空
		if (!withdrawMoney) {
			showMsg("请输入提现金额");
			return false;
		}
		//验证提现金额只能是大于0的数字
		var reg = /^(([1-9]\d*(\.\d*)?)|(0\.\d[1-9]))$/;
		if(!reg.test(withdrawMoney)){
			showMsg("请输入大于0的提现金额");
			return false;
		}
		
		//提交提现信息
		$.ajax({
            url : rootPath + "/wx/my/wxWalletWithdraw/saveWalletWithdraw",
            type : "post",
            async : false,
            dataType : 'json',
            data : {
            	withdrawMoney : withdrawMoney ,
            	accountId : accountId
            },
            //显示提交后返回的信息（添加/编辑账号成功后跳转页面)
            success : function(json) {
            	//如果返回内容不为空则提示信息
            	if(json.msg){
            		showMsg(json.msg);
            	}
                if(json.code > 0) {
    				window.location.href = rootPath + '/wx/my/wxWalletWithdraw/toWithdrawSuccessPage?accountId='+accountId+"&withdrawMoney="+withdrawMoney;
                }
            }
        });
	});
	
	//提现完成按钮跳转到个人-我的钱包页面
	$("#withdrawSuccess").on("click",function(){
		window.location.href = rootPath + "/wx/my/wxWallet/toMyWallet";
	});
});